using System;
using System.Collections.Generic;
using System.Text;

namespace Blimpbots.Recognition
{
    public class ArrayUtils
    {
        public static double Average(double[] array, int minIndex, int maxIndex)
        {
            double sum = 0;
            for (int i = minIndex; i < maxIndex; i++)
            {
                sum += array[i];
            }
            return sum / (maxIndex - minIndex);
        }

        public static double[,] JaggedTo2D(double[][] arr)
        {
            int m = arr.Length;
            int n = arr[0].Length;

            double[,] twoD = new double[m, n];
            for (int i = 0; i < m; i++)
            {
                if (arr[i].Length != n)
                    throw new Exception("Jagged array must be rectangular.");
                for (int j = 0; j < n; j++)
                    twoD[i, j] = arr[i][j];
            }

            return twoD;
        }

    }
}
